<template>
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <!-- <el-button size="mini" class="btn-add" @click="handleAdd()"
        >新增</el-button
      > -->
    </el-card>
    <div class="table-container">
      <el-table
        ref="homeAdvertiseTable"
        :data="list"
        style="width: 100%"
        v-loading="listLoading"
        border
      >
        <el-table-column label="名称" align="center">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column label="标签" align="center">
          <template slot-scope="scope">
            <el-tag v-for="(item, index) in scope.row.label" :key="index">{{
              item.commonDesc
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.$index, scope.row)"
              >编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import {
  commonList
} from '@/api/content'

export default {
  name: 'List',
  data () {
    return {
      list: [],
      listLoading: false,
      loading: false
    }
  },
  created () {
    this.getList()
  },
  methods: {
    handleAdd () {
      this.$router.push({ path: '/comment-ms/addComment' })
    },
    handleUpdate (index, row) {
      this.$router.push({
        path: '/comment-ms/updateComment',
        query: { commonType: row.commonType }
      })
    },
    getList () {
      this.listLoading = true
      commonList({ commonType: 'training' }).then((response) => {
        this.listLoading = false
        this.list.push({
          commonType: 'training',
          name: '课程',
          label: response.data
        })
      })
      commonList({ commonType: 'lecturer' }).then((response) => {
        this.listLoading = false
        this.list.push({
          commonType: 'lecturer',
          name: '讲师',
          label: response.data
        })
      })
    }
  }
}
</script>
<style scoped>
.input-width {
  width: 203px;
}
</style>
